{% extends 'AdminBundle::layout.html.twig' %}

{% block title %}人员管理列表{% endblock %}

{% block css %}
    <style>
        .mes-input{
            margin-bottom: 10px;
            width: 25%;
        }
        .mes-select{
            width: 25.2%;
            margin-bottom: 10px;
        }
        input{
            width: 90%;
        }
    </style>
{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}

    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">人员管理</span>
            </div>
            <!--<div class="top-nav top-nav-active">添加人员</div>-->
        </div>
        <div class="main-content">
            <div class="main-top">
                <div class="index-list member-m1">
                    <div class="index-total">企业联络人总数</div>
                    <div class="index-totalNum">
                        <span class="all-member"></span>个
                    </div>
                </div>
                <div class="index-list member-m2">
                    <div class="index-total" style="padding-top: 13px;">科技联络人总数</div>
                    <div class="index-totalNum">
                        <span class="teac-member"></span>个
                    </div>
                </div>
                <div class="index-list member-m3">
                    <div class="index-total">今日新增企业联络人数</div>
                    <div class="index-totalNum">
                        <span class="new-teac-member"></span>个
                    </div>
                </div>
            </div>

            <div class="mes-content">
                <div class="main-mes-top">

                    <div class="" style="overflow: hidden;">
                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" name="company_name" placeholder="请输入企业名称">
                        </div>


                        <select name="company_category_id" class="mes-select fl">
                            <option value="">请选择企业类别</option>
                            {% for item in data.category %}
                            <option value="{{ item.id }}">{{ item.company_category_name }}</option>
                            {% endfor %}
                        </select>

                        <select name="company_attribute_id" class="mes-select fl">
                            <option value="">请选择企业属性</option>
                            {% for item in data.attribute %}
                            <option value="{{ item.id }}">{{ item.company_attribute_name }}</option>
                            {% endfor %}
                        </select>

                    </div>

                    <div class="" style="overflow: hidden;">
                        <select name="admin_id" class="mes-select fl">
                            <option value="">请选择科技载体</option>
                            {% for item in data.teac_admin %}
                            <option value="{{ item.id }}">{{ item.nickname }}</option>
                            {% endfor %}
                        </select>


                        <select name="is_technology" class="mes-select fl">
                            <option value="">联络人身份属性</option>

                            <option value="1">科技联络人</option>
                            <option value="2">其他联络人</option>

                        </select>

                        <select name="status" class="mes-select fl">
                            <option value="">请选择帐号状态</option>

                            <option value="1">正常</option>
                            <option value="2">禁用</option>

                        </select>

                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released fl">企业联络人列表</div>
                    <div class="acc-operation fr">
                        <div class="fl">
                            <a class="release-btn fl" style="width:140px;margin-right: 40px;" href="{{ path('personal_edit_message',{id:'0'}) }}">
                                <div class="train-width" style="width: 96px;">
                                    <span class="me-icon fl"></span>
                                    <span class="re-text fl">添加新成员</span>
                                </div>
                            </a>
                        </div>
                        <div class="acc-opera-btn fl enable-btn all-disable-btn" data-status="1">启用账号</div>
                        <div class="acc-opera-btn fl disable-btn all-disable-btn" data-status="0">禁用账号</div>
                    </div>

                    <table class="table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th style="width: 2%;" class="center-th">
                                <input id="allcbox" type="checkbox" width="20" height="20" style="margin-top: -2px;">
                            </th>
                            <th style="width: 6%;" class="center-th">序号</th>
                            <th style="width:9%;" class="center-th">企业联络人姓名</th>
                            <th style="width: 9%" class="center-th">是否是科技联络人</th>
                            <th style="width: 11%" class="center-th">手机号</th>
                            <th style="width: 11%" class="center-th">公司名称</th>
                            <th style="width: 11%" class="center-th">企业属性</th>
                            <th style="width: 11%" class="center-th">企业类别</th>
                            <th class="center-th">科技载体</th>
                            <th class="center-th">邮箱</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>


                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">





                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}


{% block box %}{% endblock %}

{% block javascript %}
    {{ parent() }}
<script type="text/javascript">


        SidebarHighlighting('3');

        // 点击查询
        var company_name = "";
        var company_attribute_id = "";
        var company_category_id = "";
        var admin_id = "";
        var is_technology = "";
        var select_status = "";

        $('.mes-query-btn').on('click', function() {
            company_name = $("input[name='company_name']").val();
            company_attribute_id = $("select[name='company_attribute_id']").val();
            company_category_id = $("select[name='company_category_id']").val();
            admin_id = $("select[name='admin_id']").val();
            is_technology = $("select[name='is_technology']").val();
            select_status = $("select[name='status']").val();


            page_times = 0;
            addSearchAction(1);
        });

        // 全选

        $("#allcbox").click(function() {
            var sid = $('input[name="sid[]"]');
            sid.prop("checked",this.checked);

        });

        var $subBox = $("input[name='sid[]']");
        $("body").on("click","input[name='sid[]']",function(){

            $("#allcbox").prop("checked",$("input[name='sid[]']").length == $("input[name='sid[]']:checked").length ? true : false);
        });

        //重置密码
        $('body').on('click','.ta-reset', function() {
            var id = $(this).data("id");

            if(confirm('您确定要重置此密码吗？')) {
                $.post("{{ path('api_admin_personnel_reset_password') }}",{id:id},function (data) {
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, data.message, 1,'', true);
                    } else {
                        popStatus(2, data.message, 1,'', true);
                    }

                })
            }
        });

        // 单个禁用/启用
        $('body').on('click','.tab-disable', function() {

            var ids_arr = [];
            var id = $(this).data("id");
            var status = $(this).data("status");
            ids_arr.push(id);
            if(status == 1){
                var key = "您确定要启用吗？";
            } else {
                var key = "您确定要禁用吗？";
            }

            var ids = JSON.stringify(ids_arr);
            var prame = {status:status,ids:ids};

            if(confirm(key)) {
                accountStatus(prame);
            }
        });

        // 批量禁用/启用
        $(".all-disable-btn").click(function(){
            var $this = $(this);
            var status = $(this).data("status");

            if(status == 1){
                var key = "您确定要启用吗？";
            } else {
                var key = "您确定要禁用吗？";
            }

            var ids_arrs = [];
            $("table tbody tr").each(function(){
                var _this = $(this);
                if(_this.find("input[name='sid[]']").prop("checked")){

                    var id = _this.find(".tab-disable").data("id");
                    ids_arrs.push(id);
                }
            })

            if(ids_arrs.length == 0){
                popStatus(2,'请先选择人员！', 1,'', true);
                return;
            }

            console.log(ids_arrs);

            var ids = JSON.stringify(ids_arrs);
            var prame = {status:status,ids:ids};

            if(confirm(key)) {
                accountStatus(prame);
            }

        })



        function accountStatus(prame){
            $.post("{{ path('api_admin_personnel_status') }}",prame,function (data) {

                // 取消全选按钮
                $("#allcbox").prop("checked",false);
                console.log(data);
                if(data.errorCode == 0){

                    popStatus(1, data.message, 1,'', true);
                    //页码
                    $("table tbody").empty();
                    page_times = 0;
                    getList(1);

                } else {
                    popStatus(2, data.message, 1,'', true);
                }

            })
        }

        // 获取人员列表
        var page_times = 0;
        function getList(page,company_name,company_attribute_id,company_category_id,admin_id,is_technology,status){
            page_times++;

            var param = {page:page,company_name:company_name,company_attribute_id:company_attribute_id,company_category_id:company_category_id,admin_id:admin_id,is_technology:is_technology,status:status};

            $.getJSON("{{ path('api_admin_personnel_list') }}",param,function(data){

                $("table tbody").empty(); //3
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                if(allpage == 0){
                    $(".pagination").empty();
                }


                // 企业联络人总数
                $(".all-member").text(data.data.all_member_count);
                // 科技联络人总数
                $(".teac-member").text(data.data.teac_member_count);
                // 今日新增科技联络人
                $(".new-teac-member").text(data.data.new_teac_member_count);

                var item = data.data.data;
                for(var i in item){
                    var html = '';
                    var key = parseInt(i)+1;

                    var list_order_num = parseInt((parseInt(page)-1)*10+key);

                    if(item[i].technology_liaisons_status == 1){
                        var technology_status = "是";
                    } else {
                        var technology_status = "否";
                    }

                    var info_url = "{{ path('personal_edit_message',{id:'75759430662'}) }}".replace("75759430662",item[i].id);

                    if(item[i].status == 1){
                        html += '<tr>';

                    } else {
                        html += '<tr style="color: #cccccc;">';
                    }

                    var admin_name = item[i].admin_name;
                    if(admin_name == null){
                        admin_name = "无";
                    }

                    html += '<td class="center-th">';
                    html += '<input name="sid[]" type="checkbox" width="20" height="20" style="margin-top: -2px;">';
                    html += '</td>';

                    html += '<td class="a-line center-th">'+ list_order_num +'</td>';
                    html += '<td class="center-th">'+ item[i].name +'</td>';
                    html += '<td class="center-th">'+ technology_status +'</td>';
                    html += '<td class="center-th">'+ item[i].phone +'</td>';
                    html += '<td class="center-th">'+ item[i].company_full_name +'</td>';
                    html += '<td class="center-th">'+ item[i].company_attribute_name +'</td>';
                    html += '<td class="center-th">'+ item[i].company_category_name +'</td>';
                    html += '<td class="center-th">'+ admin_name +'</td>';
                    html += '<td class="center-th">'+ item[i].email +'</td>';
                    html += '<td class="center-th">';

                    if(item[i].status == 1){
                        html += '<span class="table-opera ta-reset" data-id="'+ item[i].id +'" style="display: block;">重置密码</span>';
                        html += '<a href="'+ info_url +'" class="table-opera tab-edit">编辑 |</a>';
                        html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'" data-status="0">禁用</span>';
                    } else {
                        html += '<span class="table-opera tab-enable tab-disable" data-id="'+ item[i].id +'" data-status="1">启用</span>';
                    }

                    html += '</td>';
                    html += '</tr>';

                    $("table tbody").append(html);
                }

            })
        }
        addSearchAction(1);  //4

        //5
        function addSearchAction(page){

            getList(page,company_name,company_attribute_id,company_category_id,admin_id,is_technology,select_status);
        }


</script>
{% endblock %}